﻿@{
    ViewBag.Title = "技能";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}

<div class="main layui-clear">
    <div class="wrap">
        <div class="layui-form layui-form-pane">
            <fieldset class="layui-elem-field">
                <legend>检索条件</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item">
                        <b>※不选择技术名称检索，结果集为该分类的下技术，选择技术名称检索，结果集只显示该技术名称</b>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">部门</label>
                            <div class="layui-input-block">
                                <select id="Depart" name="Depart">
                                    <option value="">请选择</option>
                                    <option value="1">一部</option>
                                    <option value="2">二部</option>
                                    <option value="3">三部</option>
                                    <option value="4">四部</option>
                                    <option value="5">五部</option>
                                    <option value="6">六部</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">技术分类</label>
                            <div class="layui-input-block">
                                <select id="SkillKind" name="SkillKind" lay-filter="SkillKind" lay-search>
                                    <option value="">请搜索</option>
                                    <option value="JapLang">日语</option>
                                    <option value="PageSkill">前端开发语言</option>
                                    <option value="ScriptLang">脚本开发语言</option>
                                    <option value="HostLang">Host系开发语言</option>
                                    <option value="OpenLang">Open系开发语言</option>
                                    <option value="DBHSkill">Host系数据库</option>
                                    <option value="DBOSkill">Open系数据库</option>
                                    <option value="PhoneSkill">移动端</option>
                                    <option value="OSSkill">操作系统</option>
                                    <option value="ServerSkill">Web服务器</option>
                                    <option value="ReportSkill">报表(帐票)</option>
                                    <option value="OtherLang">其他开发语言</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">技术名称</label>
                            <div class="layui-input-block">
                                <select id="SkillName" name="SkillName">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="float:right">
                        <a href="#" class="layui-btn layui-btn-normal" id="btnSearch">
                            <i class="layui-icon layui-icon-search"></i>检索
                        </a>                   
                        <a  id="btnExcel" href="@Url.Action("ExcelOut","SKill")" class="layui-btn layui-btn-normal">
                            <i class="fa fa-file-excel-o"></i> Excel打印
                        </a>                      
                    </div>
                </div>
            </fieldset>
        </div>
        <table id="skill" lay-filter="skill"></table>
        <script type="text/html" id="toolbar">
            <b>社员技术一览</b>
        </script>
        <script type="text/html" id="StaffNoTpl">
            <a href="#" class="layui-table-link" lay-event="edit">{{d.StaffNo || ''}}</a>
        </script>
    </div>
</div>
@section scripts{
    <script>
        layui.use(['jquery', 'table'], function () {
            var $ = layui.jquery;
            var table = layui.table;
            if (!layui.data('user').user.IsAdmin) {
                $("#btnExcel").css("display", "none");
            }    
            table.render({
                elem: '#skill'
                , height: 500
                , title: '用户技术表'
                , data: []                
                , autoSort: false
                , toolbar: '#toolbar'
                , defaultToolbar: ['filter', 'exports', 'print']
                , cols: [[
                    { type: 'numbers' }
                    , { field: 'StaffNo', title: '工号', width: 120, templet: '#StaffNoTpl' }
                    , { field: 'StaffName', title: '姓名', width: 120 }
                    , { field: 'Depart', title: '所属部门', width: 100, hide: true }
                    , { field: 'DepartName', title: '所属部门', width: 100 }
                ]]
            });

            //监听行工具事件
            table.on('tool(skill)', function (obj) {
                if (obj.event === 'edit') {
                    var data = obj.data;
                    layui.data('model', {
                        key: 'model',
                        value: {
                            uid : data.StaffNo,
                            kind: $("#SkillKind").val(),
                            sname: data.StaffName
                        }
                    });   
                    location.href = '/skill/detail';
                }
            });

            $("#btnSearch").click(function () {
                var Depart = $("#Depart").val();
                var kind = $("#SkillKind").val();
                var name = $("#SkillName").val();
                if (kind == "") {
                    layer.msg("技术分类不能为空", { icon: 2 });
                    return;
                }
                var json = [[{ type: 'numbers', fixed: 'left' }
                    , { field: 'StaffNo', title: '工号', width: 100, fixed: 'left', templet: '#StaffNoTpl' }
                    , { field: 'StaffName', title: '姓名', width: 100, fixed: 'left' }
                    , { field: 'Depart', title: '所属部门', width: 100, hide: true }
                    , { field: 'DepartName', title: '所属部门', width: 100 }
                ]];

                $.ajax({
                    url: '/Skill/SkillNames?kind=' + kind,
                    type: 'post',
                    contentType: false,
                    processData: false,
                    dataType: "json",
                    success: function (res) {
                        if (res.status == 0) {
                            var names = res.msg;
                            console.log(res);
                            for (var i = 0; i < names.length; i++) {
                                if (name != "") {
                                    if (name == names[i].val) {
                                        json[0].push({ field: names[i].val, title: names[i].text, width: 120 });
                                        break;
                                    }
                                } else {
                                    if (names[i].text == "UserId") {
                                        json[0].push({ field: names[i].val, title: names[i].text, hide: true });
                                    } else {
                                        json[0].push({ field: names[i].val, title: names[i].text, width: 120 });
                                    }
                                }
                            }

                            table.render({
                                elem: '#skill'
                                , height: 500
                                , title: '用户技术表'
                                , url: '/Skill/DataList?Depart=' + Depart + "&kind=" + kind + "&name=" + name
                                , autoSort: false
                                , page: {}
                                , toolbar: '#toolbar'
                                , limits: [10]
                                , defaultToolbar: ['filter', 'exports', 'print']
                                , cols: json
                            });
                        } else {
                            layer.msg(res.msg, { icon: 5 });
                        }
                    }
                    , error: function () {
                        layer.msg("请求异常", { icon: 5 });
                    }
                });
            });
        });
    </script>
}
